#include "queue.h"

bool queue_init(Queue* q, uint8_t* array, uint32_t capacity) {  

    q->capacity = capacity;
    q->front = q->size = 0;
    q->rear = capacity - 1;
    q->array = array;

    return true;
}

bool queue_enqueue(Queue* q, uint8_t item) {
    if (q->size == q->capacity) {
        return false;
    }
    q->rear = (q->rear + 1) % q->capacity;
    q->array[q->rear] = item;
    q->size++;
    return true;
}

uint8_t queue_dequeue(Queue* q) {
    if (q->size == 0) {
        return 0;
    }
    uint8_t item = q->array[q->front];
    q->front = (q->front + 1) % q->capacity;
    q->size--;
    return item;
}

uint32_t queue_size(Queue* q) {
    return q->size;
}

bool queue_is_empty(Queue* q) {
    return q->size == 0;
}
